package com.hsy.sunflowerbao.login.store

import com.flux.action.RxAction
import com.flux.action.RxStoreChange
import com.flux.dispatcher.Dispatcher
import com.hsy.sunflowerbao.base.action.ActionType
import com.hsy.sunflowerbao.base.action.Key
import com.hsy.sunflowerbao.base.store.BaseStore
import com.hsy.sunflowerbao.login.data.ShopsData

/**
 * 选择店铺数据缓存
 * Created on 2018/3/27.
 *
 * @author Yang
 */
class ShopsStore(dispatcher: Dispatcher) : BaseStore(dispatcher) {

    /**
     * 店铺列表
     */
    lateinit var shops: List<ShopsData>
    /**
     * 选择的店铺
     */
    lateinit var shop: ShopsData

    override fun onRxAction(action: RxAction) {
        if (handleSuper) super.onRxAction(action)
        if (action.success) {
            when (action.type) {
                ActionType.GET_SHOPS -> shops = action[Key.SHOPS_DATA]
                ActionType.SELECT_SHOP -> shop = action[Key.SHOP_RESULT]
            }
        }
        postChange(RxStoreChange(tag, action.type, action.success))
    }
}